﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SiteMaster : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session == null || Session.Count <= 0)
        {
            Response.Redirect("~/Account/Login.aspx");
        }
        if (!Page.IsPostBack)
        {

        }
        string fullName = Convert.ToString(Session["FullName"]);
        ((Label)HeadLoginView.FindControl("lblUser")).Text = "Hi <b>" + fullName + "</b> !! ";
        ((Label)HeadLoginView.FindControl("lblDate")).Text = "<b>Today is:</b> " + DateTime.Now.ToString("dddd MMMM d,  yyyy");
        CallRoleBasedPage();
    }

    private void CallRoleBasedPage()
    {
        int roleId = 0;
        roleId = Convert.ToInt32(Session["Role"]);
        MenuItem child = null;
        if (roleId == (int)Constants.UserRole.Admin)
        {
            child = new MenuItem();
            child.NavigateUrl = "~/Pages/CreateUser.aspx";
            child.Text = "Create User";
            NavigationMenu.Items.Add(child);
        }
        foreach (MenuItem item in NavigationMenu.Items)
        {
            if (item.ChildItems.Count > 0)
            {
                child = new MenuItem();

                switch (roleId)
                {
                    case (int)Constants.UserRole.Admin:
                        child.NavigateUrl = "~/Pages/Approval.aspx?Type=" + item.Value;
                        child.Text = "Approve " + item.Text;

                        break;
                    case (int)Constants.UserRole.DataEntryOperator:
                        child.NavigateUrl = "~/Pages/CreateMaster.aspx?Type=" + item.Value;
                        if (item.Value == Constants.Bill)
                        {
                           child.NavigateUrl = "~/Pages/SearchMaster.aspx?Type=BV";
                            child.Text = "View " + item.Text;
                        }
                        else
                        {
                            child.Text = "Create " + item.Text;
                        }

                        break;
                    default:
                        break;
                }
                item.ChildItems.Add(child);
            }
        }

    }
}
